package com.guguguweb.rpc.Test;

import com.guguguweb.rpc.entity.RpcRequest;
import com.guguguweb.rpc.net.client.imp.UnprocessedRequests;
import com.guguguweb.rpc.net.client.proxy.ChannelProvider;
import com.guguguweb.rpc.serializer.CommonSerializer;
import com.guguguweb.rpc.serializer.JsonSerializer;
import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.util.UUID;
import java.util.concurrent.ExecutionException;

public class NettySendMessageTest {

    private static final Logger log = LoggerFactory.getLogger(NettySendMessageTest.class);



    public static void main(String[] args) {
        ChannelProvider channelProvider = new ChannelProvider(new UnprocessedRequests());
        try {
            Channel channel = channelProvider.get(new InetSocketAddress(3371), new JsonSerializer());
            log.info("获得的channel ： {}",channel);
            RpcRequest rpcRequest = new RpcRequest();
            rpcRequest.setRequestId(UUID.randomUUID().toString());
            rpcRequest.setHeartBeat(false);
            channel.writeAndFlush(rpcRequest);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ConnectException e) {
            throw new RuntimeException(e);
        }
    }
}
